package EvaluateService

import (
	"QingDai-Gin/api/models"
	"QingDai-Gin/config"
	"gorm.io/gorm"
)

func GetAllEvaluate() ([]models.Evaluate, *gorm.DB) {
	var evaluates []models.Evaluate
	Mysql := config.Mysql()
	tx := Mysql.Table("evaluate__evaluate").Find(&evaluates)
	return evaluates, tx
}

func GetEvaluateById(id int) (models.Evaluate, *gorm.DB) {
	var evaluate models.Evaluate
	Mysql := config.Mysql()
	tx := Mysql.Table("evaluate__evaluate").First(&evaluate, id)
	return evaluate, tx
}

func GetEvaluatesByP(p map[string]any) ([]models.Evaluate, *gorm.DB) {
	var evaluates []models.Evaluate
	Mysql := config.Mysql()
	tx := Mysql.Table("evaluate__evaluate")
	for key, value := range p {
		tx.Where(key+" = ?", value)
	}
	tx.Find(&evaluates)
	return evaluates, tx
}
func GetEvaluateByP(p map[string]any) (models.Evaluate, *gorm.DB) {
	var evaluate models.Evaluate
	Mysql := config.Mysql()
	tx := Mysql.Table("evaluate__evaluate")
	for key, value := range p {
		tx.Where(key+" = ?", value)
	}
	tx.First(&evaluate)
	return evaluate, tx
}

func CreateEvaluate(evaluate models.Evaluate) {
	Mysql := config.Mysql()
	Mysql.Table("evaluate__evaluate").Create(evaluate)
}

func UpdateEvaluate(evaluate models.Evaluate) {
	Mysql := config.Mysql()
	Mysql.Table("evaluate__evaluate").Save(evaluate)
}

func DeleteEvaluate(evaluate models.Evaluate) {
	Mysql := config.Mysql()
	Mysql.Table("evaluate__evaluate").Delete(evaluate)
}
